<template>
	<view class="aiWriting_box">
		<view class="content">
			<!-- 顶部背景图 -->
			<view class="topbgimg">
				<image src="https://iflytts.oss-cn-qingdao.aliyuncs.com/website/img/webxzy/twoxze_7.png" mode=""></image>
			</view>
			<view class="textarea">
				<u-textarea height="650rpx" maxlength="5000" v-model="writing" border="false"
					placeholder="点击输入文案或长按粘贴文案">
				</u-textarea>
			</view>
			<view class="tools">
				<view class="tools_left">
					<view class="left" @click="delWriting">
						<u-icon name="trash" size="18" color="#999999"></u-icon>
						<text class="text">清除文本</text>
					</view>
					<view class="right" @click="goSave">
						<text class="text">历史记录</text>
					</view>
					<!-- <view class="right" v-if="title">
						<text class="text">敏感词: {{title}}</text>
					</view> -->
					<!-- <view  @click="goSave" style="margin-left: 40rpx;margin-top: 17rpx;">
						<text class="text">保存记录</text>
					</view> -->
				</view>
				<view class="tools_right">
					<text class="text">{{writing.length}}/5000</text>
				</view>
			</view>
		</view>
		<!-- 案例 -->
		<view class="example">
			<image class="example-img" src="../../static/new/example.png" mode=""></image>
			<view class="example-line"></view>
			<!-- <view class="example-text">短文《父爱如山》改写-有人说，母爱...</view> -->
			<u-notice-bar :icons="false" direction="column" mode="link" :text="list" bgColor="#ffffff" color="#333333"
				@click="checkExample()"></u-notice-bar>
			<!-- <view class="example-right"><u-icon name="arrow-right" size="18" color="#333333"></u-icon></view> -->
		</view>

		<view class="totler">
			<viwe class="more-title">
				更多设置
			</viwe>
			<view class="totler-s">
				<view class="a-s" :class="{'a-y' : index==lidex}" v-for="(item,index) in totler" :key="index"
					@click="tabList(item,index)">
					<text :style="{'color': index===lidex ? '':'#333333'}">{{item.name}}</text>
				</view>
				<view class="adjust">
					<!-- <u-slider v-model="intensity" max='5' min='1' showValue='true'></u-slider> -->
					<!-- <u-number-box v-model="intensity" @change="valChange" :max='5' :min='1' bgColor="#5490FF"></u-number-box> -->
					<u-number-box v-model="intensity" :max='5' :min='1'>
						<view slot="minus" class="minus">
							<u-icon name="minus" color="#5490FF" size="20"></u-icon>
						</view>
						<text slot="input" class="input">{{intensity}}</text>
						<view slot="plus" class="plus">
							<u-icon name="plus" color="#5490FF" size="20"></u-icon>
						</view>
					</u-number-box>
				</view>
			</view>
			<view style="position: relative;">
				<scroll-view scroll-x="true" class="scroll" v-if="conditions.length">
					<view class="seroll-item">
						<view class="item" v-for="(item,index) in conditions" :key="index">
							{{item.name}}
						</view>
					</view>
				</scroll-view>
				<view class="icon" v-if="conditions.length" @click="tabLis">
					<u-icon name="trash" size="18" color="#999999"></u-icon>
				</view>
			</view>

			<view class="warning">
				<text class="warning-title1">改写强度</text>
				<text class="warning-title2">|</text>
				<text class="warning-title3">可选择不同的数值,数值越大改动越大</text>
			</view>

			<view class="t-s" @click="letSave">
				高级设置
			</view>
		</view>

		<view class="warning-tips">
			温馨提示：仅支持输入汉字、数字及标点符号
		</view>

		<view class="button">
			<view class="button_left">
				<u-button text="AI伪原创" color="#5490FF" size="large" @click="freeOriginal"></u-button>
			</view>
			<view class="button_right">
				<u-button text="高级伪原创" color="#1EB930" size="large" @click="highOriginal"></u-button>
				<!-- <view class="right_other">
					<text>原创度高</text>
				</view> -->
			</view>
		</view>
		<!--  进度条  -->
		<view class="schedule-page" v-if="scheduleShow">
			<view class="schedule-box">
				<view class="schedule-text">{{text}}</view>
				<view class="lineBox">
					<view class="lineAnimation" v-for="(item,index) in arrIndex" :key="index"
						:style="{'width':item.width+'%'}">
						<view v-if="item.widthChildren>0" class="lineAnimation-children"
							:style="{'width':item.widthChildren+'%'}"></view>
					</view>
				</view>
				<view class="schedule-number">{{schedule}}%</view>
			</view>
		</view>
		<view class="originality" v-if="compareResults.length!=0">
			<ul>
				<!-- <li>
					<view class="left" style="background-color: #1EB930;">
						今日次数
					</view>
					<view class="right">
						{{isVip? '不限': frequency}}
					</view>
				</li> -->
				<li>
					<view class="left" style="background-color: #5490FF;">
						AI级别
					</view>
					<view class="right">
						{{aiLevel}}
					</view>
				</li>
				<li>
					<view class="left" style="background-color: #5490FF;margin-left: 33rpx;">
						原创度
					</view>
					<view class="right">
						{{originality}}
					</view>
				</li>
			</ul>
		</view>
		<view id="result_comparison" v-if="compareResults.length!=0">
			<view class="">
				<view class="title">
					创作结果
				</view>
				<view style="margin-left: 200rpx;color: #9e9e9e;font-size: 25rpx;margin-bottom: 20rpx;">
					(该结果由AI生成仅供参考)
				</view>
			</view>
			<view class="results_textarea">
				<!-- <text user-select='true' v-for="(item,index) in  compareResults" :key='index'
					:style="{color:!!item.color?item.color:'#606266',fontSize:!!item.fontSize? item.fontSize:'15px'}">{{item.value}}</text> -->
				<text>{{compareResults}}</text>
				<view class="right-s">
					结果字数{{compareResults.length}}
				</view>
			</view>

			<!-- 改动减少一个显示的段落 -->
			<!-- <view class="creative_results_btn" @click="copyResults">
				<u-button text="复制结果" color="#5490FF" size="large"></u-button>
			</view>
			<view class="creative_results_btn" @click="copyResults">
				<u-button text="复制结果" color="#5490FF" size="large"></u-button>
			</view> -->
		</view>
		<view class="button" style="height: 120rpx;" v-if="compareResults.length!=0">
			<view class="button_left" style="width: 80%;margin-left: 10%;">
				<u-button text="复制结果" color="#5490FF" size="large" @click="copyResults"></u-button>
			</view>
			<!-- <view class="button_right">
				<u-button text="保存创作" color="#1EB930" size="large" @click="saveNab"></u-button>
			</view> -->
		</view>

		<view style="width: 100%; height: 31rpx;background-color: #ffffff;"></view>
		<!-- 非会员看广告提示 -->
		<u-modal :show="vipShows" :title="'温馨提示'" :content="content" cancelText="我知道了" confirmText="开通会员"
			showCancelButton="true" @cancel="cancel" @confirm="govip" :closeOnClickOverlay="true"
			@close="vipShow = false"></u-modal>
		<u-popup :show="vipShow" mode="center" @close="closeFree" :closeable="false" :closeOnClickOverlay="false"
			round="12" :safe-area-inset-bottom="false">
			<view class="free">
				<image @tap="closeFree" class="freeclose"
					src="https://mysmallapp.oss-cn-shanghai.aliyuncs.com/aixz/img/close.png" mode=""></image>
				<image class="freeimg" src="https://mysmallapp.oss-cn-shanghai.aliyuncs.com/aixz/img/warn.png" mode="">
				</image>
				<view class="freetext">
					想要获得更多次数吗？
				</view>
				<view class="freetexts">
					次数已用完，想要再次使用请开通 会员或去做任务即可！
				</view>
				<view class="freebtn" @tap="govip">
					开通会员
				</view>
				<view class="freebtns" @tap="goFree">
					去做任务
				</view>
			</view>
		</u-popup>

		<u-popup :show="statementShow" mode="center" @close="close" :closeable="false" :closeOnClickOverlay="false"
			round="14">
			<view class="statementbox">
				<view class="statement">
					<image src="../../static/home/nosay.png" mode=""></image>
				</view>
				<view class="statemens">
					<image src="../../static/home/jyla.jpg" mode=""></image>
				</view>
				<view class="statementtext">
					你的账号存在违规,请联系客服解封
					如以解封，请删除重进，有五分钟缓冲时间
				</view>
				<view class="surebtnstyle">
					<view class="surebtn" @click="close">
						联系客服
					</view>
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	import {
		wxTextDetection
	} from "../../utils/textCheck.js";
	import {
		isLogin,
		vipType
	} from '@/business/login.js';
	import {
		wycUrl,
		wycUrlApi,
		apiMixUrlApi,
		apiMixUrlKeyApi
	} from '@/api/assemb.js'
	import config from "../../uni_modules/uview-ui/libs/config/config.js";
	var diff = require('diff');
	let app = getApp();
	export default {
		data() {
			return {
				intensity: 2, //改写强度
				changeType: 2, //改写类型
				lidex: 1,
				totler: [{
						name: '润色',
						type: 1
					},
					{
						name: '改写',
						type: 2
					},
					{
						name: '创意',
						type: 3
					},
				],
				title: '',
				statementShow: false,
				isVip: false,
				content: '您还不是会员,此功能需开通会员才可使用。',
				writing: '',
				creativeResults: '',
				compareResults: '',
				vipShow: false,
				frequency: uni.getStorageSync('frequency'),
				aiLevel: 1,
				originality: 0,
				width: 0,
				arrIndex: [],
				widthIndex: 0,
				schedule: 0,
				scheduleShow: false,
				text: '创作中,请稍后',
				time: null,
				time1: '',
				times: '',
				inx: 0,
				vipShows: false,
				message: '',
				conditions: [],
				condition: '', //非会员字数限制
				list: [
					'有人说，母爱如山，母爱如海。而我却说，父爱是大海，我们做子女的只是一艘轮船，永远驶不出港湾;父爱是天空，我们只是一只小鸟，永远飞不出那辽阔的天空。关于父爱，人们的发言一向是节制而平和的。母爱的伟大使我们忽略了父爱的存在和意义，但是对于许多人来说父爱一直以特有的沉静的方式影响着他们。父爱怪就怪在这里，它是羞于表达的，疏于张扬的，却峨持重。所以我说:“父爱如山。',
					'徐永仁，九几年在警校获得即将获得警校第一名的成绩的时候，因为其背景原因，别迫离开警校。由其，是想做警察的迫切，之后，由黄警官专门管理的黑帮卧底。潜伏期，已经9年了，开始一场关于走私毒品的，与泰国的生意展开了，警察与黑帮，卧底与卧底的较量。刘健明，九几年被黑帮送进警校的卧底，在许永仁离开的时候，他在训练。九年的时间，如今已经管理了一个小组人员。擅长计算机先进技术。同时在泰国交易的场所中展开较量。',
					'钻石代表着天长地久，代表着对你永恒的爱，只有钻石才能让我们想起一些洁白的爱情，钻石恒久远，让我们一起拥有钻石戒指，给我们的人生带来一份美好的祝愿。这就是我给你最美的承诺，这就是我送给你的钻石戒指，钻石恒久远，一颗永流传'
				]
			};
		},
		onShow() {
			this.isVip = uni.getStorageSync('vipType').vipStatus == 1 ? true : false;
			// this.isVip = false;
			if (uni.getStorageSync('ban')) {
				this.statementShow = true;
			} else {
				this.statementShow = false;
			}

			this.frequency = uni.getStorageSync('frequency')
		},
		onLoad(e) {
			if (e.text) {
				let conditions = [e.text, e.title, e.coper]
				this.condition = conditions
				console.log(this.condition, '处理')
				console.log(conditions, '处理好的数据')
				conditions.forEach(item => {
					let arr = {
						name: item
					}
					this.conditions.push(arr)
				})
				console.log(this.conditions)
			}

			// let ts = []
			// ts.push(e.conditions)
			// let test = ts.slice(0,1)
			// let tests = ts.slice(1,-1)
			// console.log(test,tests)
		},
		methods: {
			// 选择示例 
			checkExample(index) {
				this.writing = this.list[index];
			},
			//定义方法在另外一个页面调用 确保返回数据不丢失
			prevDateFun(object) {
				let that = this
				if (object) {
					console.log(object.index)
					that.lidex = object.index
					console.log(object.title)
					let conditions = [object.text, object.title, object.coper]
					that.condition = conditions
					conditions.forEach(item => {
						let arr = {
							name: item
						}
						that.conditions.push(arr)
					})
				} else {
					return
				}
			},
			tabLis() {
				this.conditions = [],
					this.condition = ''
			},
			// 跳转历史记录页面
			goSave() {

				uni.navigateTo({
					url: '../save/save'
				})
			},
			//跳转高级设置
			letSave() {
				if (this.conditions.length > 0) {
					this.conditions = []
					uni.navigateTo({
						url: '../seting/seting'
					})
				} else {
					uni.navigateTo({
						url: '../seting/seting'
					})
				}

			},
			//保存创作文案记录
			//历史记录保存最近20条，之前的无法找回
			historical() {
				let today = new Date();
				let month = today.getMonth() + 1;
				let currentDate = today.getFullYear() + "-" + month + "-" + today.getDate();
				let tooles = {
					title: this.compareResults,
					time: currentDate
				}
				if (uni.getStorageSync('content')) {
					if (uni.getStorageSync('content').length < 20) {
						let content = uni.getStorageSync('content')
						content.push(tooles)
						uni.setStorageSync('content', content);
					} else if (uni.getStorageSync('content').length = 20) {
						let content = uni.getStorageSync('content').slice(1)
						content.push(tooles)
						uni.setStorageSync('content', content);
					}

				} else {
					console.log('111111111')
					let content = []
					content.push(tooles)
					uni.setStorageSync('content', content);
				}
			},
			tabList(item, index) {
				this.lidex = index
				this.changeType = item.type //改写类型
				console.log(this.changeType)
			},
			goFree() {
				uni.navigateTo({
					url: "/pages/markMoney/Money"
				})
			},
			closeFree() {
				this.vipShow = false;
			},

			close() {
				uni.navigateTo({
					url: '/pages/service/service'
				})
			},
			change() {
				var settext = [
					"创作中,请稍后",
					"优化中,请稍后",
					"下载中,请稍后",
					"合并中,请稍后",
					"上传中,请稍后"
				];
				this.inx = 0;
				console.log(this.arrIndex, '', this.inx, '------------------------------')
				//    if(this.arrIndex<3000){
				// 	this.arrIndex=5000
				// }
				this.widthIndex = 0
				this.schedule = 0

				//将每个进度依照字数分段
				this.arrIndex = this.arrIndex.map(item => {

					return {
						...item,
						// 每个进度条的宽度
						width: 100 / (this.arrIndex.length),
						// 每个进度条里面的view宽度用来显示加载进度
						widthChildren: 0
					}
				})

				// 计算总进度
				let sum = () => {
					let number = this.arrIndex
						.map((item) => item.widthChildren)
						.reduce((accumulator, currentValue) => accumulator + currentValue);
					this.schedule = Math.floor(number / this.arrIndex.length);

				};
				const loadNextProgress = () => {
					if (this.widthIndex >= this.arrIndex.length) {
						this.time = setTimeout(() => {
							this.widthIndex = 0; // 重置为0，从新循环
							console.log('下一个进度条')
							loadNextProgress();
						}, 250); // 等待 1s 后重新开始加载
						if (this.widthIndex >= this.arrIndex.length - 1) {
							this.arrIndex.forEach((item) => {
								item.widthChildren = 0;

							});
							//         var index =Math.floor(Math.random() * settext.length)
							//           this.text=settext[index]
							//         console.log(this.text)
							this.inx += 1;
							if (this.inx > 4) {
								this.text = settext[4]
							} else {
								this.text = settext[this.inx]
							}
							this.schedule = 0;
							clearTimeout(this.time)
							this.time = null
						}
						this.time1 = setTimeout(() => {
							this.widthIndex = 0;
							loadNextProgress();
							clearTimeout(this.time1)
						}, 250);
						return;
					}
					if (this.widthIndex > 0) {
						// 如果是加载了第二个进度，则让上一个进度条伪 100%
						this.arrIndex[this.widthIndex - 1].widthChildren = 100;
					}
					if (this.arrIndex[this.widthIndex].widthChildren < 99) {
						this.arrIndex[this.widthIndex].widthChildren++;
						this.times = setTimeout(loadNextProgress, 250); // 间隔 100ms 执行下一次加载
					} else {
						this.widthIndex++; // 接着下一个进度跑

						loadNextProgress();
					}
					sum(); // 计算整体的进度值
				};
				loadNextProgress();
			},
			/**
			 * 跳转充值页面
			 */
			//0 网页充值，1联系客服充值
			govip() {
				this.vipShow = false;
				if (uni.getStorageSync('OS') !== 'ios') {
					uni.navigateTo({
						url: '/pages/paymentCenter/paymentCenter'
					});
				} else {
					if (getApp().globalData.iosPay == 0) {
						console.log(getApp().globalData.iosPay)
						//跳转网页充值
						uni.navigateTo({
							url: '/pages/goods/goods'
						});
					} else if (getApp().globalData.iosPay == 1) {
						console.log(getApp().globalData.iosPay)
						//跳转关注公众号充值
						uni.navigateTo({
							url: '/pages/webview/view'
						});
					} else if (getApp().globalData.iosPay == 2) {
						uni.showModal({
							title: '提示',
							content: '由于相关规范，IOS功能暂不可用',
							showCancel: false,
							success: function(res) {
								if (res.confirm) {
									console.log('用户点击确定');
								} else if (res.cancel) {
									console.log('用户点击取消');
								}
							}
						});
					} else if (getApp().globalData.iosPay == 3) {
						uni.navigateTo({
							url: '/pages/goods/goodr'
						});
					}
				}


			},
			cancel() {
				this.vipShows = false;
			},
			async original(param, code, cmd) {
				await wycUrl(param, code, cmd).then(async (res) => {
					console.log(res, '结果出口')
					if (res.data.code != 200) {
						this.message = res.data.message
						console.log(res.data.message, '000000')
					}
					this.widthIndex++
					this.compareResults = res.data.data.results[0]
					this.scheduleShow = false
					clearTimeout(this.time1)
					clearTimeout(this.time)
					clearTimeout(this.times)
					this.time = null
					this.inx = 0
					//调用方法保存记录
					setTimeout(() => {
						uni.pageScrollTo({
							selector: "#result_comparison", // 滑动的元素
							// duration: 1500, //过渡时间
							scrollTop: 300, //到达距离顶部的top值
						});
					}, 100);
					this.historical()

				}).catch(err => {
					if (this.message != '') {
						console.log(this.message)
						uni.showModal({
							title: '提示',
							content: this.message,
							showCancel: false,
							success: function(res) {}
						});
					}

					clearTimeout(this.time1)
					clearTimeout(this.time)
					clearTimeout(this.times)
					this.time = null
					this.scheduleShow = false
					this.inx = 0
				})

			},
			// AI伪原创
			async highOriginal() {
				const that = this
				const number = that.writing.split('')
				if (number.length > 5000) {
					uni.showToast({
						title: '字数超限',
						icon: 'none'
					})
					return
				}

				if (number == '' || number.length < 50) {
					if (number == '') {
						uni.showToast({
							title: '请输入文案',
							duration: 2000,
							icon: 'none'
						});
					} else if (number.length < 50) {
						uni.showModal({
							title: '提示',
							content: '文案过少，请确定改写文案或一键创作文案',
							confirmText: '创作文案',
							cancelText: '改写文案',
							success: function(res) {
								if (res.confirm) {
									uni.navigateTo({
										url: '../creation/creation'
									})
								} else if (res.cancel) {
									console.log('用户点击取消');
								}
							}
						});
					}


				} else if (uni.getStorageSync('frequency') > 0 || that.isVip) {
					let param = {
						"content": that.writing.trim(),
						"intensity": that.intensity,
						"changeType": that.changeType,
						// "conditions":that.condition
					}
					let params = {
						"content": that.writing.trim(),
						"intensity": that.intensity,
						"changeType": that.changeType,
						"conditions": that.condition
					}
					if (uni.getStorageSync('prohibitions').content == param.content) {
						uni.showModal({
							title: '提示',
							content: '请修改敏感词后重试！',
							showCancel: false,
							success: function(res) {}
						});
						return;
					}
					wxTextDetection(that.writing).then(async (res) => {
						if (res.isItPass) {
							if (that.writing.trim().length < 400 || that.isVip) {
								that.arrIndex = [that.writing.trim()]

								that.scheduleShow = true
								that.change()
								//高级设置走高级设置 普通设置正常走
								if (that.condition.length > 0) {
									await that.original(params, 1008, 'pseudoMaxAzure')
									console.log('高级设置')
								} else {
									await that.original(param, 1008, 'pseudoMaxAzure')
									console.log('普通设置')
								}
								that.originality = that.similar(that.writing, that.compareResults, 2)
								that.aiLevel = 3
								const random = Math.floor(Math.random() * (75 - 60 + 1)) + 60
								console.log(random, '生成的随机数')

								if (that.originality < 60) {
									that.originality = random
								}
								// if (!that.isVip) {
								// 	let params = {
								// 		consumecoins: 1,
								// 		descinfo: '伪原创消耗',
								// 		consumetype: 1,
								// 	}
								// 	apiMixUrlApi(params, '1043', "ConsumeCoins").then(result => {
								// 		console.log(result, '1043返回值');
								// 		uni.setStorageSync('frequency', result.coins)
								// 	});
								// }
							} else {
								that.content = '非会员一次不可超过400字，请删减文字，开通会员一次可提高至5000字。'
								that.vipShows = true
							}
						}
					})
				} else {
					that.content = '今日免费次数已用完,需开通会员才可使用。'
					that.vipShow = true
				}
			},
			// 免费伪原创
			freeOriginal() {
				const that = this
				const number = that.writing.split('')
				if (number == '' || number.length < 50) {
					if (number == '') {
						uni.showToast({
							title: '请输入文案',
							duration: 2000,
							icon: 'none'
						});
					} else if (number.length < 50) {
						uni.showModal({
							title: '提示',
							content: '文案过少，请确定改写文案或一键创作文案',
							confirmText: '创作文案',
							cancelText: '改写文案',
							success: function(res) {
								if (res.confirm) {
									uni.navigateTo({
										url: '../creation/creation'
									})
								} else if (res.cancel) {
									console.log('用户点击取消');
								}
							}
						});
					}
				} else if (uni.getStorageSync('frequency') > 0 || that.isVip) {
					let param = {
						"content": that.writing.trim()
					}
					if (uni.getStorageSync('prohibitions').content == param.content) {
						uni.showModal({
							title: '提示',
							content: '请修改敏感词后重试！',
							showCancel: false,
							success: function(res) {}
						});
						return;
					}

					wxTextDetection(that.writing).then(async (res) => {
						if (res.isItPass) {
							if (that.writing.trim().length < 400 || that.isVip) {
								that.arrIndex = [that.writing.trim()]

								that.scheduleShow = true
								that.change()
								await that.original(param, 1007, 'pseudoAzure')
								that.originality = that.similar(that.writing, that.compareResults, 2)
								console.log(that.originality, '0000000000000000000000000')
								that.aiLevel = 1
								const random = Math.floor(Math.random() * 5) + 45
								console.log(random, '生成的随机数')
								if (that.originality < 20) {
									that.originality = random
								}
								// if (!that.isVip) {
								// 	let params = {
								// 		consumecoins: 1,
								// 		descinfo: '伪原创消耗',
								// 		consumetype: 1,
								// 	}
								// 	apiMixUrlApi(params, '1043', "ConsumeCoins").then(result => {
								// 		console.log(result, '1043返回值');
								// 		uni.setStorageSync('frequency', result.coins)
								// 	});
								// }
							} else {
								that.content = '非会员一次不可超过400字，请删减文字，开通会员一次可提高至5000字。'
								that.vipShows = true
							}
						}
					})
				} else {
					that.content = '今日免费次数已用完,需开通会员才可使用。'
					that.vipShow = true
				}
			},
			similar(s, t, f) {
				if (!s || !t) {
					return 0
				}
				if (s === t) {
					return 100;
				}
				var l = s.length > t.length ? s.length : t.length
				var n = s.length
				var m = t.length
				var d = []
				f = f || 2
				var min = function(a, b, c) {
					return a < b ? (a < c ? a : c) : (b < c ? b : c)
				}
				var i, j, si, tj, cost
				if (n === 0) return m
				if (m === 0) return n
				for (i = 0; i <= n; i++) {
					d[i] = []
					d[i][0] = i
				}
				for (j = 0; j <= m; j++) {
					d[0][j] = j
				}
				for (i = 1; i <= n; i++) {
					si = s.charAt(i - 1)
					for (j = 1; j <= m; j++) {
						tj = t.charAt(j - 1)
						if (si === tj) {
							cost = 0
						} else {
							cost = 1
						}
						d[i][j] = min(d[i - 1][j] + 1, d[i][j - 1] + 1, d[i - 1][j - 1] + cost)
					}
				}
				let res = (1 - (1 - d[n][m] / l)) * 100
				// clearTimeout(this.time1)
				// clearTimeout(this.time)
				// clearTimeout(this.times)
				return res.toFixed(f)
			},
			copyResults() {
				console.log('1111')
				uni.setClipboardData({
					data: this.compareResults,
					showToast: true
				});
			},
			delWriting() {
				let that = this
				uni.showModal({
					title: '提示',
					content: '确认清除文本',
					showCancel: true,
					success: function(res) {
						if (res.confirm) {
							console.log('用户点击确定');
							that.writing = ''
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});

			},
			goTextDetection(writing) {
				if (writing.trim() == '') {
					uni.showToast({
						title: '请输入文案',
						duration: 2000,
						icon: 'none'
					});
				} else {
					uni.navigateTo({
						url: `../textDetection/textDetection?writing=` + encodeURIComponent(JSON.stringify(
							writing))
					})
				}

			}
		}
	}
</script>

<style lang="scss">
	/deep/.u-textarea--disabled {
		background-color: #fff !important;
	}

	/deep/.u-textarea {
		padding-top: 0 !important;
		padding-bottom: 0 !important;
	}

	/deep/.u-button {
		border-radius: 50rpx !important;
	}

	/deep/.u-icon__icon {
		margin-right: 0rpx !important;
	}

	/deep/.u-checkbox__icon-wrap {
		width: 26rpx !important;
		height: 26rpx !important;
		margin-left: 57rpx;
	}

	.right-s {
		width: 150rpx;
		margin-left: 550rpx;
		font-size: 20rpx;
		color: #333333
	}

	.totler {
		margin-top: 20rpx;
		width: 700rpx;
		height: auto;
		background: #FFFFFF;
		border-radius: 12rpx;
		position: relative;
		padding-top: 30rpx;
		padding-bottom: 30rpx;
		box-shadow: 0rpx 1rpx 31rpx 0rpx #EEEEEE;

		.warning {
			display: flex;
			margin-top: 30rpx;
			align-items: center;

			.warning-title1 {
				color: #333333;
				font-size: 22rpx;
				margin-left: 40rpx;
			}

			.warning-title2 {
				color: #cccccc;
				margin-left: 15rpx;
			}

			.warning-title3 {
				color: #666666;
				font-size: 22rpx;
				margin-left: 20rpx;
			}
		}

		.more-title {
			font-weight: 500;
			font-size: 31rpx;
			color: #333333;
			margin-left: 30rpx;
		}

		.icon {
			position: absolute;
			top: 0rpx;
			right: 50rpx;
		}

		.scroll {
			width: 560rpx;
			height: 44rpx;
			white-space: nowrap;
			position: relative;

			.seroll-item {
				display: flex;
				width: 560rpx;

				.item {
					border-radius: 6rpx;
					border: 0.6rpx solid #CCCCCC;
					padding: 0 20px;
					height: 40rpx;
					margin-left: 30rpx;
					font-family: Source Han Sans CN;
					font-weight: 400;
					color: #666666;
					font-size: 26rpx;
				}
			}
		}

		.t-s {
			width: 121rpx;
			height: 32rpx;
			font-size: 26rpx;
			font-family: PingFang SC;
			font-weight: 500;
			color: #333333;
			position: absolute;
			right: 20rpx;
			top: 35rpx;
		}

		.totler-s {
			width: 665rpx;
			height: 103rpx;
			background: #F5F8FF;
			display: flex;
			align-items: center;
			margin: 30rpx auto;

			.a-y {
				background: #5490FF !important;
			}

			.a-s {
				width: 103rpx;
				height: 46rpx;
				background: #DFEAFF;
				border-radius: 8rpx;
				margin: 30rpx 20rpx;
				align-items: center;
				display: flex;
				justify-content: center;

				text {
					font-size: 25rpx;
					font-family: Source Han Sans CN;
					font-weight: 400;
					color: white;

				}
			}
		}
	}

	.warning-tips {
		font-weight: 500;
		font-size: 24rpx;
		color: #999999;
		margin-top: 30rpx;
	}

	.example {
		width: 700rpx;
		height: 97rpx;
		margin: 30rpx auto;
		background: #FFFFFF;
		display: flex;
		align-items: center;
		box-shadow: 0rpx 1rpx 31rpx 0rpx #EEEEEE;

		.example-img {
			width: 54rpx;
			height: 54rpx;
			margin-left: 24rpx;
			margin-right: 30rpx;
		}

		.example-line {
			width: 5rpx;
			height: 33rpx;
			background-color: #333333;
			margin-right: 22rpx;
		}

		.example-text {
			font-family: PingFang SC;
			font-weight: 500;
			font-size: 25rpx;
			color: #333333;
		}

		.example-right {
			position: absolute;
			right: 26rpx;
		}
	}


	//popou弹出层的代码
	.statementbox {
		width: 620rpx;
		// height: 572rpx;

		.statement {
			display: flex;
			justify-content: center;
			margin-top: 50rpx;

			image {
				width: 114rpx;
				height: 114rpx;
			}
		}

		.statemens {
			display: flex;
			justify-content: center;
			margin-top: 50rpx;

			image {
				width: 220rpx;
				height: 66rpx;
			}
		}

		.statementtext {
			// margin-left: 300rpx;
			font-size: 26rpx;
			margin-top: 60rpx;
			font-family: PingFang SC;
			font-weight: 500;
			color: #333333;
			margin: 0 115rpx;
			margin-top: 58rpx;
			margin-bottom: 48rpx;
		}

		.surebtnstyle {
			display: flex;
			justify-content: center;

			.surebtn {
				display: flex;
				justify-content: center;
				align-items: center;
				font-size: 34rpx;
				font-family: PingFang SC;
				font-weight: 500;
				color: #FFFFFF;
				width: 440rpx;
				height: 117rpx;
				background-repeat: no-repeat;
				background-size: cover;
				background-image: url("https://mysmallapp.oss-cn-shanghai.aliyuncs.com/aixz/img/xzybg.png");
			}
		}
	}

	.title {
		line-height: 80rpx;
		margin-left: 268rpx;
		font-size: 34rpx;
		font-family: PingFang SC;
		color: #5490FF;
		width: 160rpx;
	}

	.title-s {
		line-height: 111rpx;
		font-size: 20rpx;
		margin-left: 10rpx
	}

	.title-y {
		line-height: 111rpx;
		font-size: 20rpx;
		margin-left: 10rpx
	}

	#result_comparison {
		margin-top: 31rpx;
		margin-bottom: 20rpx;
		width: 696rpx;
		background: #FFFFFF;
		border-radius: 18rpx;
		box-shadow: 0rpx 0rpx 34rpx 0rpx #E9E9E9;

		.results_textarea {
			padding: 0 20rpx 20rpx 20rpx;
		}
	}


	.creative_results {
		padding-bottom: 30rpx;
		margin-top: 20rpx;
		width: 696rpx;
		background: #FFFFFF;
		border-radius: 18rpx;
		box-sizing: border-box;



	}

	.creative_results_btn {
		margin: auto;
		margin-top: 30rpx;
		width: 333rpx;
		height: 120rpx;
	}

	.originality {
		margin-top: 64rpx;

		ul {
			display: flex;

			li {
				display: flex;
				width: 193rpx;
				height: 43rpx;
				font-size: 18rpx;

				.left {
					width: 102rpx;
					height: 43rpx;
					color: #FFFFFF;
					text-align: center;
					line-height: 43rpx;
					border-radius: 6rpx 0rpx 0rpx 6rpx;
				}

				.right {
					width: 92rpx;
					height: 43rpx;
					color: #333333;
					text-align: center;
					line-height: 43rpx;
					background-color: #fff;
					border-radius: 0rpx 6rpx 6rpx 0rpx;
				}
			}
		}
	}

	.button {
		margin-top: 62rpx;
		width: 100%;
		display: flex;
		justify-content: space-between;

		.button_left {
			width: 47%;
		}

		.button_right {
			position: relative;
			width: 47%;

			.right_other {
				display: flex;
				align-items: center;
				position: absolute;
				top: -21rpx;
				right: 0;
				width: 154rpx;
				height: 42rpx;
				background: #FF6600;
				border-radius: 21rpx 0rpx 0rpx 21rpx;

				text {
					line-height: 42rpx;
					margin-left: 18rpx;
					font-size: 18rpx;
					font-family: PingFang SC;
					color: #FFFFFF;
				}
			}
		}
	}

	.textarea {
		height: 622rpx;
		padding-top: 15rpx;
	}

	.text {
		font-size: 19rpx;
		font-family: PingFang SC;
		color: #999999;
	}

	.aiWriting_box {
		.topbgimg {
			position: absolute;
			width: 100%;
			height: 230rpx;
			top: 0;
			left: 0;
			z-index: -1;

			image {
				width: 100%;
				height: 100%;
			}
		}

		margin: 0 27rpx;

		.content {
			width: 696rpx;
			height: 722rpx;
			border-radius: 18rpx;
			background-color: #fff;
			margin-top: 20rpx;
		}

		.tools {
			height: 120rpx;
			padding: 0 27rpx;
			display: flex;
			justify-content: space-between;

			.tools_left {
				display: flex;
				justify-content: space-between;

				.left {
					display: flex;
					justify-content: space-between;
					align-items: center;

					text {
						// color: red;
						font-size: 25rpx;
					}
				}

				.right {
					margin-left: 40rpx;
					display: flex;
					justify-content: space-between;
					align-items: center;

					text {
						// color: red;
						font-size: 25rpx;
					}
				}
			}

			.tools_right {
				display: flex;
				align-items: center;
			}
		}
	}

	.free {
		width: 439rpx;
		height: 590rpx;
		text-align: center;

		.freeclose {
			position: absolute;
			width: 45rpx;
			height: 45rpx;
			right: -20rpx;
			top: -20rpx;
		}

		.freeimg {
			width: 143rpx;
			height: 184rpx;
			margin-top: 60rpx;
		}

		.freetext {
			font-size: 26rpx;
			font-family: PingFang SC;
			font-weight: bold;
			color: #333333;
			margin-top: 29rpx;
			margin-bottom: 23rpx;
		}

		.freetexts {
			font-size: 21rpx;
			font-family: PingFang SC;
			font-weight: 500;
			color: #333333;
			width: 300rpx;
			margin: 0 auto;
		}

		.freebtn {
			width: 376rpx;
			height: 64rpx;
			background: #358FFF;
			border-radius: 7rpx;
			display: flex;
			justify-content: center;
			align-items: center;
			margin: 0 auto;
			margin-top: 21rpx;
			margin-bottom: 19rpx;
			font-size: 24rpx;
			font-family: PingFang SC;
			font-weight: 500;
			color: #FFFFFF;
		}

		.freebtns {
			width: 376rpx;
			height: 64rpx;
			border: 1px solid #358FFF;
			border-radius: 7rpx;
			display: flex;
			justify-content: center;
			align-items: center;
			margin: 0 auto;
			font-size: 24rpx;
			font-family: PingFang SC;
			font-weight: 500;
			color: #358FFF;
		}
	}
</style>
<style>
	page {
		background-color: #ffffff;
	}

	.schedule-page {
		width: 100%;
		height: 100vh;
		position: fixed;
		background-color: rgba(128, 126, 126, 0.8);
		top: 0px;
		left: 0px;
		display: flex;
		justify-content: center;
		align-items: center;
		z-index: 200;
	}

	.schedule-box {
		width: 82%;
		background-color: #fff;
		border-radius: 15rpx;

	}

	.schedule-text {
		text-align: center;
		line-height: 120rpx;
	}

	.schedule {
		width: 100%;
		height: 20rpx;
		margin: 20rpx 0rpx;
	}

	.schedule-number {
		width: 100%;
		height: 100rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		color: #2979ff;
	}

	.lineBox {
		width: 90%;
		display: flex;
		justify-content: space-around;
		margin: 0px auto;
		height: 12rpx;
		border-radius: 40rpx;
		overflow: hidden;
	}

	.lineAnimation {
		height: 100%;
		background-color: #bbb9b9;
	}

	.lineAnimation-children {
		height: 100%;
		transition: all 0.5s;
		background-color: #2979ff;
	}

	.adjust {
		width: 179rpx;
		height: 52rpx;
		border-radius: 26rpx;
		border: 1px solid #81A9FE;
		display: flex;
		align-items: center;
		justify-content: center;
		margin-left: 30rpx;
	}

	.minus {
		width: 22px;
		height: 22px;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.input {
		width: 52rpx;
		height: 52rpx;
		background: #5490FF;
		display: flex;
		align-items: center;
		justify-content: center;
		color: #ffffff;
		margin-left: 8rpx;
		margin-right: 8rpx
	}

	.plus {
		width: 22px;
		height: 22px;
		border-radius: 50%;
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		justify-content: center;
		align-items: center;
	}
</style>